<template>
	<view >
		<u-form :model="form" ref="uForm" class="u-p-l-60 u-p-r-60" >
			<u-form-item label="姓名" prop="name" required  >
				<u-input v-model="form.name" />
				<view></view>
			</u-form-item>
		</u-form>
		<button @tap="submit" class="getCaptcha">保存</button>
	</view>
</template>
		
<script>
	export default {
		data() {
			return {
				form: {
					name: "",
				},
				rules: {
					name: [
						{
							required: true,
							message: '请输入姓名',
							trigger: ['blur', 'change']
						}
					]
				}
			};
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(async valid => {
					if (valid) {
						const res = await this.$u.api.modiUserName({name:this.form.name})
						this.$u.toast("信息修改成功")
						//更新本地用户信息
						this.$u.utils.updateUserInfo()
					} else {
						
					}
				});
			}
		},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {
			this.$refs.uForm.setRules(this.rules);
			if(this.vuex_user !== {}){
				this.form.name = this.vuex_user.name
			}
		}
	};
</script>

<style lang="scss" scoped>
	.getCaptcha {
		margin: 60rpx 80rpx;
		background-color: $u-type-warning;
		color: #fff;
		border: none;
		font-size: 30rpx;
		padding: 12rpx 0;
		
		
		
		&::after {
			border: none;
		}
	}

</style>
